package com.moco.launcher.fragment;

import java.util.ArrayList;
import java.util.List;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;

import com.moco.launcher.R;
import com.moco.launcher.bean.PickItemInfo;
import com.moco.launcher.listener.FragmentListener;
import com.moco.launcher.view.PickerView;
import com.oazon.common.util.Utils;

public class PowerBackFragment extends BaseFragment {

	private static final String TAG = "PowerBackFragment";
	private SharedPreferences mConfig;
	private List<PickItemInfo> data = new ArrayList<PickItemInfo>();

	public void registerCallback(FragmentListener l) {
		ml = l;
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		PickItemInfo item = new PickItemInfo();
		item.setText("温馨时刻");
		item.setId("0");
		data.add(item);

		item = new PickItemInfo();
		item.setText("返回之前");
		item.setId("1");
		data.add(item);

		item = new PickItemInfo();
		item.setText("露天咖啡");
		item.setId("2");
		data.add(item);

		mConfig = getContext().getSharedPreferences(Utils.CONFIG_FILE,
				getContext().MODE_PRIVATE);
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View rootView = inflater.inflate(R.layout.power_back_layout, container,
				false);
		final PickerView pv = (PickerView) rootView.findViewById(R.id.list);
		pv.setOnSelectListener(new com.moco.launcher.view.PickerView.onSelectListener() {
			@Override
			public boolean onRelayout(String selectId,
					com.moco.launcher.view.PickerView.UiParam param) {
				Log.d(TAG, "onSelected " + selectId);
				param.HlColor = 0xffee7b1d;
				return true;
			}

			@Override
			public boolean onStop(String nSelectId) {

				return false;
			}

			@Override
			public boolean onSelect(String nSelectId) {

				return false;
			}
		});

		pv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Log.d(TAG, "ONCLICK.......");
				PickerView view = (PickerView) v;

				Log.d(TAG, "view.getCurrentSelectId()=" + view.getCurrentSelectId());
				if (view.getCurrentSelectId().equals("1")) {
					if (ml != null) {
						ml.finishActivity();
					}
				}
			}
		});

		pv.setData(data);

		return rootView;
	}
}
